package com.sfpay.coreplatform.order.service.composite.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sfpay.coreplatform.order.service.composite.IHandler;
import com.sfpay.coreplatform.order.service.composite.common.PayContext;
import com.sfpay.coreplatform.order.service.exception.OrderServiceException;
import com.sfpay.coreplatform.order.service.validate.ValidateNULL;
import com.sfpay.coreplatform.order.valueobject.dto.PayRequest;
import com.sfpay.coreplatform.order.valueobject.dto.Response;
@Service
public class TradePayHandler implements IHandler {
	
	@Resource
	private TradeHandler tradeHandler;
	@Resource
	private PayHandler payHandler;

	@Transactional(rollbackFor={OrderServiceException.class},propagation=Propagation.NESTED)
	public Response Handler(PayRequest request, PayContext payContext)
			throws OrderServiceException {
		Response response=null;
		if(ValidateNULL.checkStringNull(payContext.getTradeNo())){//已经存在交易号不用进行耍再进行保存
		response=tradeHandler.Handler(request, payContext);
		}
		response=payHandler.Handler(request, payContext);
		return response;
	}

	@Override
	public String getHandlerName() {
		 
		return "TradeHandler";
	}

}
